﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using FlexiCommerce.Components;
using FlexiCommerce.Engine;
using FlexiCommerce.Installation;
using FlexiCommerce.Persistence.NH;
using NUnit.Framework;
using FlexiCommerce.Security;

namespace FlexiCommerce.Tests
{
    public class PersistenceAwareBase : ItemTestsBase
    {
        protected IEngine engine;

        [TestFixtureSetUp]
        public virtual void TestFixtureSetUp()
        {
            engine = new FlexiCommerce.Engine.Engine(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), "flexicommerce", EventBroker.Instance);
            engine.Initialize();
        }

        [TearDown]
        public override void TearDown()
        {
            base.TearDown();
            engine.Persister.Dispose();
        }

        protected virtual ContentPersister GetNHibernatePersistenceManager()
        {
            return engine.Persister as ContentPersister;
        }

        protected virtual void CreateDatabaseSchema()
        {
            InstallationManager im = engine.Resolve<InstallationManager>();
            im.Install();
        }

        protected virtual void DropDatabaseSchema()
        {
            InstallationManager im = engine.Resolve<InstallationManager>();
            im.DropDatabaseTables();
        }


    }
}
